package com.youhp.spire.xls.demo.MarkerDesigner;

import com.spire.data.table.DataTable;
import com.spire.xls.*;

public class MarkerDesigner {
    public static void main(String[] args) {
        //Create a workbook and load an Excel file from disk.
        Workbook workbook = new Workbook();
        workbook.loadFromFile("data/MarkerDesigner.xls");

        //Get the first worksheet.
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Fill parameter.
        workbook.getMarkerDesigner().addParameter("Variable1",1234.5678);

        //Fill DataTable.
        workbook.getMarkerDesigner().addDataTable("Country",LoadForm1());
        workbook.getMarkerDesigner().apply();

        //Set the worksheet AutoFit property.
        sheet.getAllocatedRange().autoFitRows();
        sheet.getAllocatedRange().autoFitColumns();

        //Save to file.
        workbook.saveToFile("output/MarkerDesigner.xlsx", ExcelVersion.Version2013);
    }

    private static DataTable LoadForm1()
    {
        //Create a workbook and load an Excel file from disk.
        Workbook workbook = new Workbook();
        workbook.loadFromFile("data/MarkerDesigner-DataSample.xls");

        //Initialize worksheet.
        Worksheet sheet = workbook.getWorksheets().get(0);
        return sheet.exportDataTable();
    }
}
